# dependencies
library(tidyverse)
library(scales)
library(stringr)
library(effectsize)
library(janitor)
library(knitr)
library(kableExtra)in US adults, 2008-2012. NHANES CDC data.
library(NHANES)
data(NHANES)
dat <- NHANES |>
filter(Age >= 18) |>
filter(!is.na(Height) & !is.na(Weight))
ggplot(dat, aes(Weight, Height)) +
geom_point(alpha = 0.1)dat |>
summarize(n = n(),
cor = broom::tidy(cor.test(Weight, Height, use = "pairwise.complete.obs"))) |>
unnest(cor) |>
select(n, r = estimate, ci_lower = conf.low, ci_upper = conf.high) |>
mutate_if(is.numeric, janitor::round_half_up, digits = 2) |>
kable() |>
kable_classic(full_width = FALSE)| n | r | ci_lower | ci_upper |
|---|---|---|---|
| 7414 | 0.45 | 0.43 | 0.47 |
dat |>
group_by(Gender) |>
summarize(n = n(),
cor = broom::tidy(cor.test(Weight, Height, use = "pairwise.complete.obs"))) |>
unnest(cor) |>
select(n, r = estimate, ci_lower = conf.low, ci_upper = conf.high) |>
mutate_if(is.numeric, janitor::round_half_up, digits = 2) |>
kable() |>
kable_classic(full_width = FALSE)| n | r | ci_lower | ci_upper |
|---|---|---|---|
| 3763 | 0.28 | 0.25 | 0.31 |
| 3651 | 0.39 | 0.36 | 0.42 |
dat <- NHANES |>
filter(Age >= 18) |>
filter(!is.na(Gender) & !is.na(Height) & !is.na(Weight))
dat |>
summarize(n = n()) |>
kable() |>
kable_classic(full_width = FALSE)| n |
|---|
| 7414 |
Weight:
##
## Cohen's d
##
## d estimate: -0.6685073 (medium)
## 95 percent confidence interval:
## lower upper
## -0.7152995 -0.6217151
Height:
##
## Cohen's d
##
## d estimate: -1.869864 (large)
## 95 percent confidence interval:
## lower upper
## -1.924451 -1.815276